package com.sky.mapper;

import com.sky.dto.ShoppingCartItemDTO;
import com.sky.entity.ShoppingCartItem;
import com.sky.entity.ShoppingCartItem;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {
    /**
     * 根据用户id查询有没有该项商品
     * @return
     */
    List<ShoppingCartItem> list(ShoppingCartItem shoppingCartItem);

    /**
     * 根据购物车id更新商品数量，因为这个项目里一个购物车是一个商品
     * @param shoppingCartItem
     */
    @Update("update shopping_cart_item set number=#{number} where id=#{id}")
    void updateNumberById(ShoppingCartItem shoppingCartItem);

    /**
     * 插入一项商品
     * @param shoppingCartItem
     */

    @Insert("insert into shopping_cart_item(name,user_id,dish_id,setmeal_id,dish_flavor,number,amount,image,create_time) values(#{name},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{image},#{createTime})")
    void insert(ShoppingCartItem shoppingCartItem);

    //只能用已经写好的addShoppingCart那个动态条件查询方法！！！
    @Select("select * from shopping_cart_item where user_id=#{userId}")
    List<ShoppingCartItem> showShoppingCart(ShoppingCartItem shoppingCartItem);

    @Delete("delete from shopping_cart_item where user_id=#{userId}")
    void cleanShoppingCart(ShoppingCartItem shoppingCartItem);
}
